using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Instedd.Labs.Forms.Library;
using System.IO;

public partial class GetCsvSurveys : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // The header is included by default.
        GenerateCsv(!(Request["h"] == "no"));
    }

    void GenerateCsv(bool includeHeader)
    {
        Response.Clear();

        Response.AppendHeader("Content-Disposition", "filename=BioForms.csv;attachment");
        Response.Buffer = false;
        Response.ContentType = "application/text";
        Response.ContentEncoding = Encoding.UTF8;

        using(StreamWriter writer = new StreamWriter(Response.OutputStream))
        {
            SurveyManager.GetInstance().WriteAllSurveysUsingCsvFormat(writer, includeHeader);
            writer.Flush();
        }
        
        Response.End();
    }

}
